<?php
namespace app\admin\model;

use think\Loader;
use think\Model;

class Admin extends Model
{
    //设置当前模型对应的完整数据表名称
    protected $table = 'tp_admin';

    /**
     * @param $data
     * 登录认证
     */
    public function pass($data){

        //执行验证
        $validate = Loader::validate('Admin');
        if(!$validate->check($data)){
            return ['valid'=>0,'msg'=>$validate->getError()];
        }

        $pwd = md5($data['passwd']);
        $user_info = $this->where(array('username'=>$data['username'],'pwd'=>$pwd))->find();
        //登录失败
        if(!$user_info){

            return ['valid'=>0,'msg'=>'用户名或密码错误'];
        }
        //登录成功
        //保存入session
        session('admin',$user_info);
        return ['valid'=>1,'msg'=>'登录成功'];

    }





}





